---
import "../styles/global.css";
import Navigation from "../components/Navigation";
import { GOOGLE_ANALYTICS_ID } from "../config";

export interface Props {
	title: string;
	description?: string;
	ogImage?: string;
	ogImageAlt?: string;
	noindex?: boolean;
}

const {
	title,
	description,
	ogImage = "https://cidr.xyz/og.webp",
	ogImageAlt = "Color-coded octets illustrating an IP range and CIDR mask",
	noindex = false,
} = Astro.props;
---

<html lang="en">
	<head>
		<meta charset="utf-8" />
		<link rel="icon" type="image/x-icon" href="/ico/favicon.ico" />
		<link
			rel="apple-touch-icon"
			sizes="180x180"
			href="/ico/apple-touch-icon.png"
		/>
		<link
			rel="icon"
			type="image/png"
			sizes="192x192"
			href="/ico/icon-192.png"
		/>
		<link
			rel="icon"
			type="image/png"
			sizes="512x512"
			href="/ico/icon-512.png"
		/>
		<link rel="manifest" href="/manifest.json" />
		<meta name="theme-color" content="#0066cc" />
		<meta name="viewport" content="width=device-width" />
		<link rel="sitemap" href="/sitemap-index.xml" />
		<title>{title}</title>
		{description && <meta name="description" content={description} />}

		<meta
			name="robots"
			content={noindex ? "noindex, follow" : "index, follow"}
		/>
		<link rel="canonical" href={`https://cidr.xyz${Astro.url.pathname}`} />

		{
			!noindex && (
				<>
					<meta property="og:title" content={title} />
					{description && (
						<meta property="og:description" content={description} />
					)}
					<meta property="og:type" content="website" />
					<meta
						property="og:url"
						content={`https://cidr.xyz${Astro.url.pathname}`}
					/>
					<meta property="og:site_name" content="CIDR.xyz" />
					<meta property="og:image" content={ogImage} />
					<meta property="og:image:type" content="image/webp" />
					<meta property="og:image:width" content="1200" />
					<meta property="og:image:height" content="630" />
					<meta property="og:image:alt" content={ogImageAlt} />

					<meta name="twitter:card" content="summary_large_image" />
					<meta name="twitter:title" content={title} />
					{description && (
						<meta
							name="twitter:description"
							content={description}
						/>
					)}
					<meta name="twitter:image" content={ogImage} />
				</>
			)
		}

		<script
			defer
			data-domain="cidr.xyz"
			src="https://track.mgcmnd.net/js/script.js"></script>
		<script
			async
			src={`https://www.googletagmanager.com/gtag/js?id=${GOOGLE_ANALYTICS_ID}`}
		></script>
		<script define:vars={{ GOOGLE_ANALYTICS_ID }} is:inline>
			window.dataLayer = window.dataLayer || [];
			function gtag() {
				dataLayer.push(arguments);
			}
			gtag("js", new Date());
			gtag("config", GOOGLE_ANALYTICS_ID);
		</script>

		<slot name="head" />
	</head>
	<body class="flex flex-col min-h-screen">
		<div
			class="flex-grow flex flex-col items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 p-2 w-full"
		>
			<Navigation client:idle />
			<div class="max-w-6xl w-full sm:p-8 p-2 min-h-[800px]">
				<slot />
			</div>
		</div>

		<footer class="w-full py-12 pb-20 bg-gray-800 text-gray-200">
			<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
				<div class="grid grid-cols-1 md:grid-cols-4 gap-8">
					<div class="md:col-span-1">
						<h3 class="text-lg font-semibold mb-4">CIDR.xyz</h3>
						<p class="text-sm">
							A modern CIDR calculator and subnet visualization
							tool.
						</p>
						<p class="pt-4 text-xs">
							&copy; {new Date().getFullYear()} Magic Monad. All rights
							reserved.
						</p>
					</div>
					<div>
						<h3 class="text-lg font-semibold mb-4">Resources</h3>
						<ul class="space-y-2 text-sm">
							<li>
								<a
									href="/subnet-guide/"
									class="text-gray-400 hover:text-white"
									>Subnet Guide</a
								>
							</li>
							<li>
								<a
									href="/embed-widget/"
									class="text-gray-400 hover:text-white"
									>Embed Widget</a
								>
							</li>
							<li>
								<a
									href="/privacy-policy/"
									class="text-gray-400 hover:text-white"
									>Privacy Policy</a
								>
							</li>
						</ul>
					</div>
					<div>
						<h3 class="text-lg font-semibold mb-4">Links</h3>
						<ul class="space-y-2 text-sm">
							<li>
								<a
									href="https://namekit.app/"
									class="text-gray-400 hover:text-white"
									>AI Domain Name Search</a
								>
							</li>
							<li>
								<a
									href="https://eternitybits.com/"
									class="text-gray-400 hover:text-white"
									>Immutable Document Timestamps</a
								>
							</li>
						</ul>
					</div>
					<div>
						<h3 class="text-lg font-semibold mb-4">About</h3>
						<ul class="space-y-2 text-sm">
							<li>
								Source code on <a
									href="https://github.com/yuvadm/cidr.xyz"
									class="text-gray-400 hover:text-white"
									>Github</a
								>
							</li>
							<li>
								Created by <a
									href="https://yuv.al/"
									class="text-gray-400 hover:text-white"
									>Yuval Adam</a
								>
							</li>
							<li>
								Operated by <a
									href="https://magicmonad.com/"
									class="text-gray-400 hover:text-white"
									>Magic Monad</a
								>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</footer>
	</body>
</html>
